home *** CD-ROM | disk | FTP | other *** search
- unit Unit5_1;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Menus, IniFiles, ExtCtrls, StdCtrls, Buttons, Spin,
- {今回修正分}
- Unit5_2, Unit5_3, Unit5_4, Unit5_5;
- {今回修正分ここまで}
-
- type
- TForm1 = class(TForm)
- Panel5: TPanel;
- SpeedButton1: TSpeedButton;
- Timer1: TTimer;
- Mati: TSpinEdit;
- Label6: TLabel;
- Label7: TLabel;
- Nokori: TLabel;
- MainMenu1: TMainMenu;
- K1: TMenuItem;
- Toroku: TMenuItem;
- Sakujo: TMenuItem;
- FileMenu: TMenuItem;
- EndMenu: TMenuItem;
- NewMenu: TMenuItem;
- N1: TMenuItem;
- KH1: TMenuItem;
- KR1: TMenuItem;
- KS1: TMenuItem;
- KA1: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure EndMenuClick(Sender: TObject);
- procedure TorokuClick(Sender: TObject);
- procedure SakujoClick(Sender: TObject);
- procedure NewMenuClick(Sender: TObject);
- procedure KH1Click(Sender: TObject);
- procedure KS1Click(Sender: TObject);
- procedure KR1Click(Sender: TObject);
- procedure KA1Click(Sender: TObject);
- private
- { Private 宣言 }
- Start_Time : LongInt;
- Position : Integer;
- FormList : Array[1..4] Of TForm2; {子フォームを保管する}
- KaitoJun : Array[1..4] Of Integer; {キーを押した順を保管する}
- FormCount : Integer; {子フォームの数を保管する}
- UpHeight : Integer; {上下に動ける幅を保管}
- {今回追加分}
- Procedure KaitousyaTuika(Namae : String);
- {今回追加分ここまで}
- public
- { Public 宣言 }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Timer1.Enabled := False;
-
- {今回追加分}
- Application.CreateForm(TForm3, Form3);
- Form3.ShowModal;
- Form3.Free;
- {今回追加分ここまで}
-
- Nokori.Caption := ' 0.000';
- Mati.Value := 5;
- FormCount := 0;
- end;
-
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- var
- i : Integer;
- begin
-
- {子フォームの表示を出題待ち状態に}
- For i := 1 To FormCount Do
- FormList[i].Clear;
-
- {解答順をクリア}
- For i := 1 To 4 Do
- KaitoJun[i] := -1;
-
- Panel5.SetFocus;
-
- Start_Time := GetTickCount;
- Position := 0;
-
- Nokori.Caption := Format('%3d',[Mati.Value]) + '.000';
- Timer1.Enabled := True;
-
- end;
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- S : Single;
- i, j, k : Integer;
- begin
- S := Mati.Value - (GetTickCount - Start_Time) / 1000;
- If (S <= 0) Or (Position >= FormCount) Then
- Begin
- Timer1.Enabled := False;
- Nokori.Caption := ' 0.000';
-
- If Position = 0 Then
- ShowMessage('時間切れです')
- Else
- Begin
- For i := 1 To FormCount Do
- If KaitoJun[i] >= 0 Then
- Begin
- j := KaitoJun[i];
- k := MessageDlg(FormList[j].Caption + 'さんの解答は正解ですか?',
- mtConfirmation, mbYesNoCancel, 0);
- Case k Of
- mrCancel : Exit;
-
- mrYes :
- Begin
- {子フォームのSeikaiメソッドの呼び出し}
- FormList[j].Seikai(UpHeight);
- Exit;
- End;
- {子フォームのHuSeikaiメソッドの呼び出し}
- mrNo : FormList[j].HuSeikai(UpHeight);
- End;
- End;
- End;
- End
- Else
- Nokori.Caption := Format('%7.3f',[S]);
- end;
-
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- i : Integer;
- begin
- If Not Timer1.Enabled Then
- Exit;
-
- Case Key Of
- VK_F1 :
- Begin
- Inc(Position);
- i := 1;
- End;
- VK_F5 :
- Begin
- Inc(Position);
- i := 2;
- End;
- VK_F9 :
- Begin
- Inc(Position);
- i := 3;
- End;
- VK_F12 :
- Begin
- Inc(Position);
- i := 4;
- End;
- End;
-
- If i <= FormCount Then
- Begin
- {子フォームのPushメソッドの呼び出し}
- FormList[i].Push(Position);
- KaitoJun[Position] := i;
- End;
-
- end;
-
- procedure TForm1.EndMenuClick(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TForm1.TorokuClick(Sender: TObject);
- {今回削除分}
- {var
- i : Integer;
- L, T : Integer;}
- {今回削除分ここまで}
- begin
- If TorokuDlg.ShowModal <> mrOK Then
- Exit;
- {今回修正分}
- KaitousyaTuika(TorokuDlg.Namae.Text);
-
- End;
-
- Procedure TForm1.KaitousyaTuika(Namae : String);
- var
- i : Integer;
- L, T : Integer;
- Begin
-
- FormCount := FormCount + 1;
-
- i := FormCount;
- FormList[i] := TForm2.Create(Self);
-
- FormList[i].Caption := Namae;
- {今回修正分ここまで}
- FormList[i].Tag := i;
-
- {親フォームにバランス良く子フォームを配置}
- L := (Form1.ClientWidth - FormCount * FormList[i].Width) Div (FormCount + 1);
- T := Form1.ClientHeight - Panel5.Height - FormList[i].Height;
-
- UpHeight := T Div 10;
-
- For i := 1 To FormCount Do
- FormList[i].SetBounds((i - 1) * (FormList[i].Width + L) + L,
- T,
- FormList[i].Width,
- FormList[i].Height);
-
- {子フォームが配置されたので、削除メニューを有効に}
- Sakujo.Enabled := True;
-
- {同じく、出題ボタンを有効に}
- SpeedButton1.Enabled := True;
-
- {子フォームが4つになったらそれ以上登録できないように}
- {登録メニューを無効に}
- If FormCount >= 4 Then
- Toroku.Enabled := False;
-
- end;
-
- procedure TForm1.SakujoClick(Sender: TObject);
- var
- i, j : Integer;
- L, T : Integer;
- begin
- If MessageDlg('解答者' + ActiveMDIChild.Caption + 'を削除してよろしいですか?',
- mtConfirmation, mbOkCancel, 0) <> mrOk Then
- Exit;
-
- {TagプロパティからFormList配列の添え字を知る}
- j := ActiveMDIChild.Tag;
-
- {FormList配列の空きをつめる}
- For i := j To 3 Do
- FormList[i] := FormList[i + 1];
-
- FormCount := FormCount - 1;
-
- {子フォームを閉じる}
- ActiveMDIChild.Close;
-
- {親フォームにバランス良く子フォームを再配置}
- L := (Form1.ClientWidth - FormCount * ActiveMDIChild.Width) Div (FormCount + 1);
- T := Form1.ClientHeight - Panel5.Height - ActiveMDIChild.Height;
-
- For i := 1 To FormCount Do
- Begin
- FormList[i].SetBounds((i - 1) * (FormList[i].Width + L) + L,
- T,
- FormList[i].Width,
- FormList[i].Height);
- FormList[i].Tag := i;
- End;
-
- {1つ減ったら登録メニューを有効に}
- Toroku.Enabled := True;
-
- {子フォームが無くなったら削除メニューを無効に}
- If FormCount < 1 Then
- Begin
- Sakujo.Enabled := False;
- SpeedButton1.Enabled := False;
- End;
-
- end;
-
- procedure TForm1.NewMenuClick(Sender: TObject);
- var
- i : Integer;
- begin
- For i := 1 To FormCount Do
- FormList[i].Close;
-
- FormCount := 0;
-
- Toroku.Enabled := True;
- Sakujo.Enabled := False;
- SpeedButton1.Enabled := False;
- end;
-
- {今回追加分}
- procedure TForm1.KH1Click(Sender: TObject);
- var
- i : Integer;
- begin
- For i := 1 To FormCount Do
- Begin
- FormList[i].HuSeikai(UpHeight);
- FormList[i].Clear;
- End;
- end;
-
- procedure TForm1.KS1Click(Sender: TObject);
- var
- i : Integer;
- F : TextFile;
- Path : String;
- Pos : Array[0..3] Of Integer;
- Namae : String;
- begin
- If MDIChildCount = 0 Then
- Exit;
-
- Path := ExtractFilePath(Application.ExeName);
-
- AssignFile(F, Path + 'AgeSage.Dat');
- ReWrite(F);
-
- WriteLn(F, MDIChildCount);
- For i := 1 To MDIChildCount Do
- Begin
- WriteLn(F, FormList[i].Caption);
- WriteLn(F, StrToInt(FormList[i].Tokuten.Caption) Div 1000);
- End;
- WriteLn(F, Mati.Value);
-
- CloseFile(F);
- end;
-
- procedure TForm1.KR1Click(Sender: TObject);
- var
- i, Cnt : Integer;
- F : TextFile;
- Path : String;
- Pos : Array[1..4] Of Integer;
- Namae : String;
- begin
- For i := 0 To MDIChildCount - 1 Do
- MDIChildren[0].Free;
-
- FormCount := 0;
-
- Path := ExtractFilePath(Application.ExeName);
-
- AssignFile(F, Path + 'AgeSage.Dat');
- Reset(F);
-
- ReadLn(F, Cnt);
- For i := 1 To Cnt Do
- Begin
- ReadLn(F, Namae);
- ReadLn(F, Pos[i]);
- KaitousyaTuika(Namae);
- FormList[i].Tokuten.Caption := IntToStr(Pos[i] * 1000);
- End;
- ReadLn(F, i);
- Mati.Value := i;
-
- For i := 1 To Cnt Do
- FormList[i].Top := FormList[i].Top - Pos[i] * UpHeight;
-
- CloseFile(F);
- end;
-
- {今回追加分ここまで}
- procedure TForm1.KA1Click(Sender: TObject);
- begin
- AboutBox.ShowModal;
- end;
-
- end.
-